package com.sm.controller;

import com.sm.entity.ResultMap;
import com.sm.entity.UserInfo;
import com.sm.entity.Wages;
import com.sm.entity.WagesLevel;
import com.sm.service.WagesService;
import com.sm.utils.ExcelUtil;
import com.sun.imageio.plugins.common.I18N;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/admin/wages")
public class WagesController {

    @Autowired
    ResultMap resultMap;
    @Autowired
    WagesService wagesService;

    @ResponseBody
    @RequestMapping("wageslevel")
    public ResultMap wagesLevel() throws Exception {
        List<WagesLevel> wagesLevels = wagesService.findwagesLevel();
        resultMap.setResult("levels",wagesLevels);
        return resultMap;
    }

    @ResponseBody
    @RequestMapping("settlement")
    public ResultMap wagesSettlement()throws Exception{
        wagesService.wagesSettlement();
        resultMap.setMessage("工资结算成功");
        return resultMap;
    }

    @ResponseBody
    @RequestMapping("searchone")
    public ResultMap searchOne(Integer flag,String value)throws Exception{
//        System.out.println("flag: "+flag+" value: "+value);
//        System.out.println();
        if(value == null ||value.equals("")){
            resultMap.setMessage("查询条件错误");
            return resultMap;
        }
        if(flag == 1) {
            resultMap.setResult("user",wagesService.findOneWages(value,null));
        }else if(flag == 2){
            resultMap.setResult("user",wagesService.findOneWages(null,value));
        }else {
            resultMap.setMessage("查询条件错误");
            return resultMap;
        }
        return resultMap;
    }

    @ResponseBody
    @RequestMapping("modwages")
    public ResultMap wagesModify(UserInfo userInfo)throws Exception{
//        System.out.println(userInfo);
        wagesService.updateSalaryOrLevel(userInfo);
        resultMap.setMessage("更新成功");
        return resultMap;
    }

    @ResponseBody
    @RequestMapping("outexcel")
    public ResultMap outExcel()throws Exception{
        wagesService.outExcel();
        resultMap.setMessage("导出成功");
        return resultMap;
    }

}
